﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IISView.ucStatistics
{
    public partial class ucIP : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            InitSiteList();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string SiteType = "";
            if (this.rbtnTel.Checked) SiteType = "1";
            if (this.rbtnUni.Checked) SiteType = "0";
            if (SiteType == "")
            {
                QT.Tools.Alert("请选择网站线路类型");
                return;
            }

            Regex regex = null;
            DateTime datetime = new DateTime();
            if (!DateTime.TryParse(this.tbDate.Text, out datetime))
            {
                QT.Tools.Alert("日期格式不正确");
                return;
            }

            regex = new Regex(@"^\d+$");
            if (!regex.IsMatch(this.tbTop.Text))
            {
                QT.Tools.Alert("请输入正确的数字");
                return;
            }
            if (int.Parse(this.tbTop.Text) < 0 || int.Parse(this.tbTop.Text) > 2000)
            {
                QT.Tools.Alert("请输入0-2000以内的数字，0代表查询全部记录");
                return;
            }

            DataTable dt = MyIIS.DBO.getAnalybyIP(this.tbDate.Text, this.ddlSite.SelectedValue, SiteType, int.Parse(this.tbTop.Text));
            this.gvResult.DataSource = dt;
            this.gvResult.DataBind();
            this.lblCount.Text = dt.Rows.Count.ToString();
        }

        private void InitSiteList()
        {
            DataTable dt = MyIIS.DBO.getUsing();
            this.ddlSite.DataTextField = "sitename";
            this.ddlSite.DataValueField = "guid";
            this.ddlSite.DataSource = dt;
            this.ddlSite.DataBind();
        }
    }
}